<?php
namespace App\Http\Controllers\H5;

use App\Service\H5\WhywService;
use Illuminate\Http\Request;

class WhywController extends BaseController
{
    //列表
    public function index(Request $request)
    {
        $pas['uid'] = $request->post('uid', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $res = WhywService::index($pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //详情
    public function getOne(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['uid'] = $request->post('uid', 0);
        $res = WhywService::getOne($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //任务列表
    public function getTaskList(Request $request)
    {
        $in_day = $request->post('in_day', '');
        $depart_id = $request->post('depart_id', 0);
        $res = WhywService::getTaskList($in_day, $depart_id);
        if (empty($res)) {
            return self::toJson(-2, '没有数据');
        }
        return self::toJson(0, '', $res);
    }

    //设置工时
    public function setByItem(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['item_id'] = $request->post('item_id', 0);
        $pas['task_id'] = $request->post('task_id', 0);
        $pas['role_id'] = $request->post('role_id', 0);
        $pas['depart_id'] = $request->post('depart_id', 0);
        $pas['staff_id'] = $request->post('uid', 0);
        $pas['in_day'] = $request->post('in_day', 0);
        $res = WhywService::setByItem($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //保存
    public function save(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['in_day'] = $request->post('in_day', 0);
        $pas['task_id'] = $request->post('task_id', 0);
        $res = WhywService::save($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //发布
    public function pub(Request $request)
    {
        $id = $request->post('id', 0);
        $pas['in_day'] = $request->post('in_day', 0);
        $pas['task_id'] = $request->post('task_id', 0);
        $res = WhywService::pub($id, $pas);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

   //删除
   public function del(Request $request)
   {
       $id = $request->post('id', 0);
       $res = WhywService::del($id);
       if ($res['code'] < 0) {
           return self::toJson(-2, $res['msg']);
       }
       return self::toJson();
   }

    //审核列表
    public function authList(Request $request)
    {
        $res = WhywService::authList();
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //已审核列表
    public function authOkList(Request $request)
    {
        $res = WhywService::authOkList();
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson(0, '', $res['data']);
    }

    //审核动作
    public function authSet(Request $request)
    {
        $id = $request->post('id', 0);
        $status = $request->post('status', 0);
        $remark = $request->post('remark', '');
        $res = WhywService::authSet($id, $status, $remark);
        if ($res['code'] < 0) {
            return self::toJson(-2, $res['msg']);
        }
        return self::toJson();
    }
}